package com.example.ch12implicitintents

import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menu?.add("网页")
        menu?.add("地图")
        menu?.add("电话本")
        return super.onCreateOptionsMenu(menu)
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        var m_uri: Uri
        var m_intent:Intent = Intent()

        when(item?.toString()){
            "网页" -> {
                m_uri = Uri.parse("https://www.baidu.com")
                m_intent = Intent(Intent.ACTION_VIEW,m_uri)
            }
            "地图" -> {

            }

            "电话本" -> {
                m_uri = Uri.parse("tel:13425555716")
                m_intent = Intent(Intent.ACTION_DIAL,m_uri)
            }
        }

        startActivity(m_intent)
        return true
    }
}
